/****************************************************
文件：DStaticFunc.cs
作者：UnitySir
邮箱：zouajck@foxmail.com
日期：2021/03/22 20:24:37
功能：Nothing
*****************************************************/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace DSFramework
{
    public static class DStaticFunc
    {
        #region 方形转圆形

        public static Vector3 Rect2Round(Vector3 input)
        {
            Vector3 output = Vector3.zero;
            output.x = input.x * Mathf.Sqrt(1 - (input.z * input.z) / 2.0f);
            output.z = input.z * Mathf.Sqrt(1 - (input.x * input.x) / 2.0f);
            return output;
        }

        public static Vector2 Rect2Round(Vector2 input)
        {
            Vector2 output = Vector2.zero;
            output.x = input.x * Mathf.Sqrt(1 - (input.y * input.y) / 2.0f);
            output.y = input.y * Mathf.Sqrt(1 - (input.x * input.x) / 2.0f);
            return output;
        }

        #endregion

        #region UI跟随物体

        /// <summary>
        /// UI 跟随物体
        /// </summary>
        /// <param name="mainCamera">观察游戏对象的相机</param>
        /// <param name="uiCamera">观察UI的相机</param>
        /// <param name="ui">需要在3D物体上显示的 UI</param>
        /// <param name="obj">需要显示的3D物体</param>
        /// <param name="canvas">画布</param>
        public static void UI_Follow_Model_Camera(Camera mainCamera, Camera uiCamera, RectTransform ui, GameObject obj, Transform canvas)
        {
            Vector2 screenPoint = mainCamera.WorldToScreenPoint(obj.Pos());
            Vector2 pos;
            bool isRect = RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform) canvas.transform, screenPoint, uiCamera, out pos);
            if (isRect)
            {
                if (ui != null)
                {
                    ui.RectPos(pos);
                }
            }
        }

        #endregion

        #region 显示的字体颜色

        /// <summary>
        /// 蓝色字体
        /// </summary>
        /// <param name="txt"></param>
        /// <returns></returns>
        public static string Blue(this string obj)
        {
            return $"<color=#0000ff>{obj}</color>";
        }

        /// <summary>
        /// 黄色字体
        /// </summary>
        /// <param name="txt"></param>
        /// <returns></returns>	
        public static string Yellow(this string obj)
        {
            return $"<color=#FFFF00>{obj}</color>";
        }

        /// <summary>
        /// 猩红色字体
        /// </summary>
        /// <param name="txt"></param>
        /// <returns></returns>
        public static string Red(this string obj)
        {
            return $"<color=#DC143C>{obj}</color>";
        }

        /// <summary>
        /// 适中的碧绿色	
        /// </summary>
        /// <param name="txt"></param>
        /// <returns></returns>
        public static string Green(this string obj)
        {
            return $"<color=#00FA9A>{obj}</color>";
        }

        /// <summary>
        /// 纯白色
        /// </summary>
        /// <param name="txt"></param>
        /// <returns></returns>
        public static string Write(this string obj)
        {
            return $"<color=#FFFFFF>{obj}</color>";
        }

        /// <summary>
        /// 烟白色
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string WriteSmoke(this string obj)
        {
            return $"<color=#F5F5F5>{obj}</color>";
        }

        /// <summary>
        /// 柠檬薄纱	
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string LemonChiffon(this string obj)
        {
            return $"<color=#FFFACD>{obj}</color>";
        }

        /// <summary>
        /// 橙红色	
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string OrangeRed(this string obj)
        {
            return $"<color=#FF4500>{obj}</color>";
        }

        /// <summary>
        /// 番茄
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string Tomato(this string obj)
        {
            return $"<color=#FF6347>{obj}</color>";
        }

        /// <summary>
        /// 金色
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string Gold(this string obj)
        {
            return $"<color=#FFD700>{obj}</color>";
        }

        #endregion
    }
}